﻿#include "GUISolverSettingDialog.h"
#include "ui_GUISolverSettingDialog.h"

#include "FITK_Kernel/FITKCore/FITKActionOperator.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppSettings.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Component/FITKRadiossData/FITKRadiossCase.h"
#include "FITK_Component/FITKRadiossData/FITKRadiossSolverSettings.h"

#include <QLineEdit>
#include <QLabel>
#include <QCheckBox>
#include <QComboBox>

namespace GUI
{
    GUISolverSettingDialog::GUISolverSettingDialog(Core::FITKActionOperator* oper, QWidget *parent) :
        GUIDialogBase(parent),
        _oper(oper),
        _ui(new Ui::GUISolverSettingDialog)
    {
        _ui->setupUi(this);
        // 设置对话框关闭时自动删除
        setAttribute(Qt::WA_DeleteOnClose);
        //去掉问号
        Qt::WindowFlags flags = windowFlags();
        flags &= ~Qt::WindowContextHelpButtonHint;
        setWindowFlags(flags);
        Radioss::FITKRadiossCase* caseData = FITKAPP->getGlobalData()->getPhysicsData<Radioss::FITKRadiossCase>();
        if (caseData)
            _solverSettings = caseData->getSolverSettings();
        //初始化
        this->init();
        //设置窗口自适应隐藏组件
        this->layout()->setSizeConstraint(QLayout::SetMinAndMaxSize);
    }

    GUISolverSettingDialog::~GUISolverSettingDialog()
    {
        if (_ui) {
            delete _ui;
            _ui = nullptr;
        }
    }

    void GUISolverSettingDialog::on_pushButton_Cancel_clicked()
    {
        this->reject();
    }

    void GUISolverSettingDialog::on_pushButton_OK_clicked()
    {
        this->setRunExeTimeParam();
        this->setGlobalTimeParam();
        this->setNodalTimeStepControlParam();
        this->setElementalTimeStepControlParam();
        this->setAdaptiveDynamicRelaxation();
        this->setAMSElementalTimeStepControlParam();
        this->setComputationControlParam();
        this->setConvergenceCriteriaParam();

        this->accept();
    }
    void GUISolverSettingDialog::init()
    {
        if (!_solverSettings) return;
        this->initRunExeTimeParamTreeNode();
        this->initGlobalTimeParamTreeNode();
        this->initNodalTimeStepControlParamTreeNode();
        this->initElementalTimeStepControlParamTreeNode();
        this->initAdaptiveDynamicRelaxationTreeNode();
        this->initAMSElementalTimeStepControlParamTreeNode();
        this->initComputationControlParamTreeNode();
        this->initConvergenceCriteriaParamTreeNode();

        _ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
        _ui->treeWidget->expandAll();
    }
    void GUISolverSettingDialog::initRunExeTimeParamTreeNode()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverRunExeTimeParam* runExeTimeParam = _solverSettings->getRunExeTimeParam();
        if (!runExeTimeParam) return;
        ChildTreeNodeData childItemData;
        QTreeWidgetItem* runExeTimeParamRoot = this->addTopLevelItem(QObject::tr("Run Execution Time Parameters"));
        childItemData.setText(QObject::tr("Final time"));
        childItemData.setEnableCheckBox(false);
        childItemData.setEnableLineEdit(true, "Final_time", QString::number(runExeTimeParam->getFinalTime()), "s");
        this->addChildItem(runExeTimeParamRoot, childItemData);
    }
    void GUISolverSettingDialog::initGlobalTimeParamTreeNode()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverGlobalTimeParam* globalTimeParam = _solverSettings->getGlobalTimeParam();
        if (!globalTimeParam) return;

        ChildTreeNodeData childItemData;
        QTreeWidgetItem* globalTimeParamRoot = this->addTopLevelItem(QObject::tr("Global Time Step Parameters"));
        childItemData.setText(QObject::tr("Minimum time step"));
        childItemData.setEnableCheckBox(true, "MinTime_step_CheckBox", globalTimeParam->isEnableMinTimeStep());
        childItemData.setEnableLineEdit(true, "MinTime_step_Data", QString::number(globalTimeParam->getMinTimeStep()), "s");
        this->addChildItem(globalTimeParamRoot, childItemData);
        childItemData.setText(QObject::tr("Scale factor"));
        childItemData.setEnableCheckBox(true, "Scale_factor_CheckBox", globalTimeParam->isEnableScaleFactor());
        childItemData.setEnableLineEdit(true, "Scale_factor_Data", QString::number(globalTimeParam->getScaleFactor()), "s");
        this->addChildItem(globalTimeParamRoot, childItemData);
    }
    void GUISolverSettingDialog::initNodalTimeStepControlParamTreeNode()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverNodalTimeStepControlParam * nodalParam =  _solverSettings->getNodalTimeStepControlParam();
        if (!nodalParam) return;

        ChildTreeNodeData childItemData;
        QTreeWidgetItem* nodalTimeStepRoot = this->addTopLevelItem(QObject::tr("Nodal Time Step Control Parameters"));

        childItemData.setText(QObject::tr("Time step control type"));
        childItemData.setEnableComboBox(true, "Nodal_ControlType_ComboBox",
            QStringList() << QObject::tr("Solver Default" )<< QObject::tr("CST") << QObject::tr("SET") << QObject::tr("STOP"),
            QList<int>()<< Radioss::FITKRadiossSolverNodalTimeStepControlParam::NodalTimeStep_SolverDefault << Radioss::FITKRadiossSolverNodalTimeStepControlParam::NodalTimeStep_CST << Radioss::FITKRadiossSolverNodalTimeStepControlParam::NodalTimeStep_SET << Radioss::FITKRadiossSolverNodalTimeStepControlParam::NodalTimeStep_STOP ,
            nodalParam->getTimeStepControlType());
        this->addChildItem(nodalTimeStepRoot, childItemData);

        childItemData.setText(QObject::tr("Minimum time step"));
        childItemData.setEnableLineEdit(true, "Nodal_MinTimeStep_Edit", QString::number(nodalParam->getMinimumTimeStep()), "s");
        this->addChildItem(nodalTimeStepRoot, childItemData);
        childItemData.setText(QObject::tr("Scale factor"));
        childItemData.setEnableLineEdit(true, "Nodal_ScaleFactor_Edit", QString::number(nodalParam->getScaleFactor()), "");
        this->addChildItem(nodalTimeStepRoot, childItemData);
        childItemData.setText(QObject::tr("Initial added mass ratio"));
        childItemData.setEnableLineEdit(true, "Nodal_InitAddMassRatio_Edit", QString::number(nodalParam->getInitialAddMassRatio()), "");
        this->addChildItem(nodalTimeStepRoot, childItemData);
    }
    void GUISolverSettingDialog::initElementalTimeStepControlParamTreeNode()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverElementalTimeStepControlParam* elementalParam = _solverSettings->getElementalTimeStepControlParam();
        if (!elementalParam) return;
        ChildTreeNodeData childItemData;
        QTreeWidgetItem* elementalTimeStepRoot = this->addTopLevelItem(QObject::tr("Elemental Time Step Control Parameters"));

        childItemData.setText(QObject::tr("Time step control type"));
        childItemData.setEnableComboBox(true, "Elemental_ControlType_ComboBox",
            QStringList() << QObject::tr("Solver Default") << QObject::tr("CST") << QObject::tr("DEL") << QObject::tr("STOP"),
            QList<int>() << Radioss::FITKRadiossSolverElementalTimeStepControlParam::ElementalTimeStep_SolverDefault << Radioss::FITKRadiossSolverElementalTimeStepControlParam::ElementalTimeStep_CST << Radioss::FITKRadiossSolverElementalTimeStepControlParam::ElementalTimeStep_DEL << Radioss::FITKRadiossSolverElementalTimeStepControlParam::ElementalTimeStep_STOP ,
            elementalParam->getTimeStepControlType());
        this->addChildItem(elementalTimeStepRoot, childItemData);

        childItemData.setText(QObject::tr("Minimum time step"));
        childItemData.setEnableLineEdit(true, "Elemental_MinTimeStep_Edit", QString::number(elementalParam->getMinimumTimeStep()), "s");
        this->addChildItem(elementalTimeStepRoot, childItemData);
        childItemData.setText(QObject::tr("Scale factor"));
        childItemData.setEnableLineEdit(true, "Elemental_ScaleFactor_Edit", QString::number(elementalParam->getScaleFactor()), "");
        this->addChildItem(elementalTimeStepRoot, childItemData);
        childItemData.setText(QObject::tr("Number of additional cards"));
        childItemData.setEnableLineEdit(false);
        childItemData.setEnableCheckBox(true, "Elemental_AddCards_CheckBox", elementalParam->getNumberOfAddCards());
        this->addChildItem(elementalTimeStepRoot, childItemData);
        childItemData.setText(QObject::tr("Minimum aspect ratio"));
        childItemData.setEnableCheckBox(false);
        childItemData.setEnableLineEdit(true, "Elemental_MinAspectRatio_Edit", QString::number(elementalParam->getMinAspectRatio()), "");
        this->addChildItem(elementalTimeStepRoot, childItemData);
        childItemData.setText(QObject::tr("Minimum volume ratio"));
        childItemData.setEnableCheckBox(false);
        childItemData.setEnableLineEdit(true, "Elemental_MinVolumeRatio_Edit", QString::number(elementalParam->getMinVolumeRatio()), "");
        this->addChildItem(elementalTimeStepRoot, childItemData);
    }
    void GUISolverSettingDialog::initAdaptiveDynamicRelaxationTreeNode()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverAdaptiveDynamicRelaxation* adrParam = _solverSettings->getAdaptiveDynamicRelaxation();
        if (!adrParam) return;
        ChildTreeNodeData childItemData;
        QTreeWidgetItem* adrRoot = this->addTopLevelItem(QObject::tr("Adaptive Dynamic Relaxation"));
        childItemData.setText(QObject::tr("Enable dynamic relaxation"));
        childItemData.setEnableCheckBox(true, "ADR_Enable_CheckBox", adrParam->getEnableDynamicRelaxation());
        this->addChildItem(adrRoot, childItemData);
        childItemData.setText(QObject::tr("Start Time"));
        childItemData.setEnableCheckBox(true, "ADR_EnableStartTime_CheckBox", adrParam->isEnableStartTime());
        childItemData.setEnableLineEdit(true, "ADR_StartTime_Edit", QString::number(adrParam->getStartTime()), "s");
        this->addChildItem(adrRoot, childItemData);
        childItemData.setText(QObject::tr("Stop Time"));
        childItemData.setEnableCheckBox(true, "ADR_EnableStopTime_CheckBox", adrParam->isEnableStopTime());
        childItemData.setEnableLineEdit(true, "ADR_StopTime_Edit", QString::number(adrParam->getStopTime()), "s");
        this->addChildItem(adrRoot, childItemData);
    }
    void GUISolverSettingDialog::initAMSElementalTimeStepControlParamTreeNode()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverAMSElementalTimeStepControlParam* amsParam = _solverSettings->getAMSElementalTimeStepControlParam();
        if (!amsParam) return;
        ChildTreeNodeData childItemData;
        QTreeWidgetItem* amsRoot = this->addTopLevelItem(QObject::tr("AMS Elemental Time Step Control Parameters"));
        // Critical time step scale factor
        childItemData.setText(QObject::tr("Critical time step scale factor"));
        childItemData.setEnableCheckBox(true, "AMS_CriticalScale_CheckBox", amsParam->isEnableCriticalTimeStepScaleFactor());
        childItemData.setEnableLineEdit(true, "AMS_CriticalScale_Edit", QString::number(amsParam->getCriticalTimeStepScaleFactor()), "");
        this->addChildItem(amsRoot, childItemData);
        // Minimum time step
        childItemData.setText(QObject::tr("Minimum time step"));
        childItemData.setEnableCheckBox(true, "AMS_MinTimeStep_CheckBox", amsParam->isEnableMinTimeStep());
        childItemData.setEnableLineEdit(true, "AMS_MinTimeStep_Edit", QString::number(amsParam->getMinTimeStep()), "s");
        this->addChildItem(amsRoot, childItemData);
        // AMS convergence tolerance
        childItemData.setText(QObject::tr("AMS convergence tolerance"));
        childItemData.setEnableCheckBox(true, "AMS_ConvergenceTol_CheckBox", amsParam->isEnableAMSConvergenceTolerance());
        childItemData.setEnableLineEdit(true, "AMS_ConvergenceTol_Edit", QString::number(amsParam->getAMSConvergenceTolerance()), "");
        this->addChildItem(amsRoot, childItemData);
        // Max iterations conjugate gradient
        childItemData.setText(QObject::tr("Maximum iterations conjugate gradient"));
        childItemData.setEnableCheckBox(true, "AMS_MaxIterations_CheckBox", amsParam->isEnableMaxIterationsConjugateGradient());
        childItemData.setEnableLineEdit(true, "AMS_MaxIterations_Edit", QString::number(amsParam->getMaxIterationsConjugateGradient()), "");
        this->addChildItem(amsRoot, childItemData);
        // Number of additional outputs
        childItemData.setText(QObject::tr("Number of additional outputs"));
        childItemData.setEnableCheckBox(true, "AMS_AdditionalOutputs_CheckBox", amsParam->isEnableNumberOfAdditionalOutputs());
        childItemData.setEnableLineEdit(true, "AMS_AdditionalOutputs_Edit", QString::number(amsParam->getNumberOfAdditionalOutputs()), "");
        this->addChildItem(amsRoot, childItemData);
    }
    void GUISolverSettingDialog::initComputationControlParamTreeNode()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverComputationControlParam* controlParam = _solverSettings->getComputationControlParam();
        if(!controlParam)return;
        ChildTreeNodeData childItemData;
        QTreeWidgetItem* computationControlParamRoot = this->addTopLevelItem(QObject::tr("Computation control parameters"));
        childItemData.setText(QObject::tr("Stop computation when negative volume"));
        childItemData.setEnableLineEdit(false);
        childItemData.setEnableCheckBox(true, "Stop_c_negative_Volume", controlParam->getStopComputationWhenNegativeVolume());
        this->addChildItem(computationControlParamRoot, childItemData);
        childItemData.setText(QObject::tr("Parallel arithmetic"));
        childItemData.setEnableLineEdit(false);
        childItemData.setEnableCheckBox(true, "Parallel_arithmetic", controlParam->getParallelArithmetic());
        this->addChildItem(computationControlParamRoot, childItemData);
    }
    void GUISolverSettingDialog::initConvergenceCriteriaParamTreeNode()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverConvergenceCriteriaParam* convergenceParam = _solverSettings->getConvergenceCriteriaParam();
        if (!convergenceParam) return;
        ChildTreeNodeData childItemData;
        QTreeWidgetItem* convergenceRoot = this->addTopLevelItem(QObject::tr("Convergence Criteria Parameters"));
        // Stop computation
        childItemData.setText(QObject::tr("Stop Computation"));
        childItemData.setEnableCheckBox(true, "Convergence_StopComputation_CheckBox", convergenceParam->getStopComputation());
        this->addChildItem(convergenceRoot, childItemData);
        // Energy error ratio
        childItemData.setText(QObject::tr("Energy error ratio"));
        childItemData.setEnableCheckBox(false);
        childItemData.setEnableLineEdit(true, "Convergence_EnergyErrorRatio_Edit", QString::number(convergenceParam->getEnergyErrorRatio()), "");
        this->addChildItem(convergenceRoot, childItemData);
        // Total mass ratio
        childItemData.setText(QObject::tr("Total mass ratio"));
        childItemData.setEnableCheckBox(false);
        childItemData.setEnableLineEdit(true, "Convergence_TotalMassRatio_Edit", QString::number(convergenceParam->getTotalMassRatio()), "");
        this->addChildItem(convergenceRoot, childItemData);
        // Nodal mass ratio
        childItemData.setText(QObject::tr("Nodal mass ratio"));
        childItemData.setEnableCheckBox(false);
        childItemData.setEnableLineEdit(true, "Convergence_NodalMassRatio_Edit", QString::number(convergenceParam->getNodalMassRatio()), "");
        this->addChildItem(convergenceRoot, childItemData);
        // Write time history file
        childItemData.setText(QObject::tr("Write time history file"));
        childItemData.setEnableLineEdit(false);
        childItemData.setEnableCheckBox(true, "Convergence_WriteTimeHistory_CheckBox", convergenceParam->getWriteTimeHistoryFile());
        this->addChildItem(convergenceRoot, childItemData);
        // Write animation file
        childItemData.setText(QObject::tr("Write animation file"));
        childItemData.setEnableLineEdit(false);
        childItemData.setEnableCheckBox(true, "Convergence_WriteAnimation_CheckBox", convergenceParam->getWriteAnimationFile());
        this->addChildItem(convergenceRoot, childItemData);
        // Energy error
        childItemData.setText(QObject::tr("Energy error"));
        childItemData.setEnableLineEdit(false);
        childItemData.setEnableCheckBox(true, "Convergence_EnergyError_CheckBox", convergenceParam->getEnergyError());
        this->addChildItem(convergenceRoot, childItemData);
    }



    QTreeWidgetItem * GUISolverSettingDialog::addTopLevelItem(const QString & text)
    {
        if (text.isEmpty()) return nullptr;
        QTreeWidgetItem* item = new QTreeWidgetItem();
        item->setText(0, text);
        _ui->treeWidget->addTopLevelItem(item);
        return item;
    }
    QTreeWidgetItem * GUISolverSettingDialog::addChildItem(QTreeWidgetItem * p, const ChildTreeNodeData & childItemData)
    {
        if (!p || childItemData._text.isEmpty()) return nullptr;
        //创建子节点数据
        QTreeWidgetItem* item = new QTreeWidgetItem(p);
        item->setText(0, childItemData._text);
        //创建窗口
        QWidget* widget = new QWidget(this);
        QHBoxLayout* layout = new QHBoxLayout();
        widget->setLayout(layout);
        //创建交互逻辑
        if (childItemData._isEnableCheckBox && !childItemData._isEnableLineEdit)
        {
            QCheckBox* checkBox = new QCheckBox(this);
            checkBox->setObjectName(childItemData._checkBox_objectName);
            checkBox->setCheckState((childItemData._checkBox_Data ? Qt::CheckState::Checked : Qt::CheckState::Unchecked));
            QLabel* qlabel = new QLabel(this);
            qlabel->setText((childItemData._checkBox_Data ? "True" : "False"));
            layout->addWidget(checkBox);
            layout->addWidget(qlabel);
            layout->setStretch(1, 1);
            connect(checkBox, &QCheckBox::stateChanged, [=](int state) {
                if (state == Qt::CheckState::Checked)
                    qlabel->setText("True");
                else
                    qlabel->setText("False");
            });
        }
        else if (!childItemData._isEnableCheckBox && childItemData._isEnableLineEdit)
        {
            QLineEdit* lineEdit = new QLineEdit(this);
            lineEdit->setObjectName(childItemData._lineEdit_objectName);
            lineEdit->setText(childItemData._lineEdit_Data);
            QLabel* qlabel = new QLabel(this);
            qlabel->setText(childItemData._unit);
            layout->addWidget(lineEdit);
            layout->addWidget(qlabel);
            layout->setStretch(1, 1);
        }
        else if (childItemData._isEnableCheckBox && childItemData._isEnableLineEdit)
        {
            QCheckBox* checkBox = new QCheckBox(this);
            checkBox->setObjectName(childItemData._checkBox_objectName);
            checkBox->setCheckState((childItemData._checkBox_Data ? Qt::CheckState::Checked : Qt::CheckState::Unchecked));
            QLineEdit* lineEdit = new QLineEdit(this);
            lineEdit->setObjectName(childItemData._lineEdit_objectName);
            lineEdit->setText(childItemData._lineEdit_Data);
            QLabel* qlabel = new QLabel(this);
            qlabel->setText(childItemData._unit);
            lineEdit->setEnabled((childItemData._checkBox_Data ? true : false));
            layout->addWidget(checkBox);
            layout->addWidget(lineEdit);
            layout->addWidget(qlabel);
            layout->setStretch(2, 1);

            connect(checkBox, &QCheckBox::stateChanged, [=](int state) {
                if (state == Qt::CheckState::Checked)
                    lineEdit->setEnabled(true);
                else
                    lineEdit->setEnabled(false);
            });
        }
        else if (childItemData._isEnableComboBox && childItemData._comboBox_ItemDatas.size() == childItemData._comboBox_items.size())
        {
            QComboBox* comboBox = new QComboBox(this);
            comboBox->setObjectName(childItemData._comboBox_objectName);
            for (int i = 0; i < childItemData._comboBox_ItemDatas.size(); ++i)
            {
                comboBox->addItem(childItemData._comboBox_items[i], childItemData._comboBox_ItemDatas[i]);
            }
            layout->addWidget(comboBox);
            int index = comboBox->findData(childItemData._comboBox_Data);
            if(index < 0)
                comboBox->setCurrentIndex(0);
            else
                comboBox->setCurrentIndex(index);
        }
        _ui->treeWidget->setItemWidget(item, 1, widget);
        return item;
    }

    bool GUISolverSettingDialog::getCheckBoxState(const QString& objectName)
    {
        QCheckBox* checkBox = findChild<QCheckBox*>(objectName);
        return checkBox ? checkBox->isChecked() : false;
    }

    double GUISolverSettingDialog::getLineEditValue(const QString& objectName)
    {
        QLineEdit* lineEdit = findChild<QLineEdit*>(objectName);
        return lineEdit ? lineEdit->text().toDouble() : 0.0;
    }

    int GUISolverSettingDialog::getTimeStepControlType(const QString& objectName)
    {
        QComboBox* comboBox = findChild<QComboBox*>(objectName);
        if (!comboBox) return 0;

        int data = comboBox->currentData().toInt();
        return data;
    }

    void GUISolverSettingDialog::setRunExeTimeParam()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverRunExeTimeParam* runExeTimeParam = _solverSettings->getRunExeTimeParam();
        if (!runExeTimeParam) return;
        runExeTimeParam->setFinalTime(getLineEditValue("Final_time"));
    }
    void GUISolverSettingDialog::setGlobalTimeParam()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverGlobalTimeParam* globalTimeParam = _solverSettings->getGlobalTimeParam();
        if (!globalTimeParam) return;
        globalTimeParam->setEnableMinTimeStep(getCheckBoxState("MinTime_step_CheckBox"));
        globalTimeParam->setMinTimeStep(getLineEditValue("MinTime_step_Data"));
        globalTimeParam->setEnableScaleFactor(getCheckBoxState("Scale_factor_CheckBox"));
        globalTimeParam->setScaleFactor(getLineEditValue("Scale_factor_Data"));
    }
    void GUISolverSettingDialog::setNodalTimeStepControlParam()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverNodalTimeStepControlParam * nodalParam = _solverSettings->getNodalTimeStepControlParam();
        if (!nodalParam) return;
        nodalParam->setTimeStepControlType(Radioss::FITKRadiossSolverNodalTimeStepControlParam::NodalTimeStepControlType(getTimeStepControlType("Nodal_ControlType_ComboBox")));
        nodalParam->setMinimumTimeStep(getLineEditValue("Nodal_MinTimeStep_Edit"));
        nodalParam->setScaleFactor(getLineEditValue("Nodal_ScaleFactor_Edit"));
        nodalParam->setInitialAddMassRatio(getLineEditValue("Nodal_InitAddMassRatio_Edit"));
    }
    void GUISolverSettingDialog::setElementalTimeStepControlParam()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverElementalTimeStepControlParam* elementalParam = _solverSettings->getElementalTimeStepControlParam();
        if (!elementalParam) return;
        elementalParam->setTimeStepControlType(Radioss::FITKRadiossSolverElementalTimeStepControlParam::ElementalTimeStepControlType(getTimeStepControlType("Elemental_ControlType_ComboBox")));
        elementalParam->setMinimumTimeStep(getLineEditValue("Elemental_MinTimeStep_Edit"));
        elementalParam->setScaleFactor(getLineEditValue("Elemental_ScaleFactor_Edit"));
        elementalParam->setNumberOfAddCards(getCheckBoxState("Elemental_AddCards_CheckBox"));
        elementalParam->setMinAspectRatio(getLineEditValue("Elemental_MinAspectRatio_Edit"));
        elementalParam->setMinVolumeRatio(getLineEditValue("Elemental_MinVolumeRatio_Edit"));
    }
    void GUISolverSettingDialog::setAdaptiveDynamicRelaxation()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverAdaptiveDynamicRelaxation* adrParam = _solverSettings->getAdaptiveDynamicRelaxation();
        if (!adrParam) return;
        adrParam->setEnableDynamicRelaxation(getCheckBoxState("ADR_Enable_CheckBox"));
        adrParam->setEnableStartTime(getCheckBoxState("ADR_EnableStartTime_CheckBox"));
        adrParam->setStartTime(getLineEditValue("ADR_StartTime_Edit"));
        adrParam->setEnableStopTime(getCheckBoxState("ADR_EnableStopTime_CheckBox"));
        adrParam->setStopTime(getLineEditValue("ADR_StopTime_Edit"));
    }
    void GUISolverSettingDialog::setAMSElementalTimeStepControlParam()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverAMSElementalTimeStepControlParam* amsParam = _solverSettings->getAMSElementalTimeStepControlParam();
        if (!amsParam) return;
        amsParam->setEnableCriticalTimeStepScaleFactor(getCheckBoxState("AMS_CriticalScale_CheckBox"));
        amsParam->setCriticalTimeStepScaleFactor(getLineEditValue("AMS_CriticalScale_Edit"));
        amsParam->setEnableMinTimeStep(getCheckBoxState("AMS_MinTimeStep_CheckBox"));
        amsParam->setMinTimeStep(getLineEditValue("AMS_MinTimeStep_Edit"));
        amsParam->setEnableAMSConvergenceTolerance(getCheckBoxState("AMS_ConvergenceTol_CheckBox"));
        amsParam->setAMSConvergenceTolerance(getLineEditValue("AMS_ConvergenceTol_Edit"));
        amsParam->setEnableMaxIterationsConjugateGradient(getCheckBoxState("AMS_MaxIterations_CheckBox"));
        amsParam->setMaxIterationsConjugateGradient(getLineEditValue("AMS_MaxIterations_Edit"));
        amsParam->setEnableNumberOfAdditionalOutputs(getCheckBoxState("AMS_AdditionalOutputs_CheckBox"));
        amsParam->setNumberOfAdditionalOutputs(getLineEditValue("AMS_AdditionalOutputs_Edit"));
    }
    void GUISolverSettingDialog::setComputationControlParam()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverComputationControlParam* controlParam = _solverSettings->getComputationControlParam();
        if (!controlParam)return;
        controlParam->setStopComputationWhenNegativeVolume(getCheckBoxState("Stop_c_negative_Volume"));
        controlParam->setParallelArithmetic(getCheckBoxState("Parallel_arithmetic"));
    }
    void GUISolverSettingDialog::setConvergenceCriteriaParam()
    {
        if (!_solverSettings) return;
        Radioss::FITKRadiossSolverConvergenceCriteriaParam* convergenceParam = _solverSettings->getConvergenceCriteriaParam();
        if (!convergenceParam) return;
        convergenceParam->setStopComputation(getCheckBoxState("Convergence_StopComputation_CheckBox"));
        convergenceParam->setEnergyErrorRatio(getLineEditValue("Convergence_EnergyErrorRatio_Edit"));
        convergenceParam->setTotalMassRatio(getLineEditValue("Convergence_TotalMassRatio_Edit"));
        convergenceParam->setNodalMassRatio(getLineEditValue("Convergence_NodalMassRatio_Edit"));
        convergenceParam->setWriteTimeHistoryFile(getCheckBoxState("Convergence_WriteTimeHistory_CheckBox"));
        convergenceParam->setWriteAnimationFile(getCheckBoxState("Convergence_WriteAnimation_CheckBox"));
        convergenceParam->setEnergyError(getCheckBoxState("Convergence_EnergyError_CheckBox"));
    }

}

